package com.lanhe.third.controller;

import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.utils.file.FileUploadUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 第三方-Oss存储
 *
 * @author zhanggl
 * @date 2023年12月2日
 */
@RestController
@RequestMapping(value = {"/api/third/file","/third/file"})
public class FileController extends BaseController {

	@Resource
	FileUploadUtils fileUploadUtils;

	@PostMapping("/upload")
	public AjaxResult upload(MultipartFile file) throws Exception {

		String url = fileUploadUtils.uploadToOss(file);
		Map<String, String> map = new HashMap<>();
		map.put("url", url);
		return success(map);
	}

	/**
	 * 获取AliYunSTSService（获取STS临时token）
	 *
	 * @return java.lang.String
	 * @author zhanggl
	 * @date 2023/12/19
	 */
	@GetMapping("/getSts")
	public AjaxResult getSts() {
		return success(fileUploadUtils.getOssSts());
	}

}
